import * as types from '../mutation_types';

export const setCurrentUser = ({ commit }, user) => {
  localStorage.setItem('currentUser', JSON.stringify(user));
  commit(types.SET_CURRENT_USER, user);
};

export const setShowingUser = ({ commit }, user = {}) => {
  commit(types.SET_SHOWING_USER, user);
};

export const removeShowingUser = ({ commit }) => {
  commit(types.SET_SHOWING_USER, {});
};

export const removeCurrentUser = ({ commit }) => {
  localStorage.removeItem('currentUser');
  commit(types.SET_CURRENT_USER, {});
};

export const setUnreadCommentsCount = ({ commit }, count) => {
  commit(types.SET_UNREAD_COMMENTS_COUNT, count);
};

export const setUnreadVotesCount = ({ commit }, count) => {
  commit(types.SET_UNREAD_VOTES_COUNT, count);
};

export const setUnreadAnncCount = ({ commit }, count) => {
  commit(types.SET_UNREAD_ANNC_COUNT, count);
};

export const setUnreadOtherCount = ({ commit }, count) => {
  commit(types.SET_UNREAD_OTHER_COUNT, count);
};

export const setCurrentSpace = ({ commit }, space) => {
  localStorage.setItem('currentSpace', JSON.stringify(space));
  commit(types.SET_CURRENT_SPACE, space);
};

export const setCurrentSpaceSidebarStatistics = ({ commit }, statistics) => {
  commit(types.SET_CURRENT_SPACE_SIDEBAR_STATISTICS, statistics);
};

export const setCurrentDocument = ({ commit }, doc = {}) => {
  commit(types.SET_CURRENT_DOCUMENT, doc);
};

export const removeCurrentDocument = ({ commit }) => {
  commit(types.SET_CURRENT_DOCUMENT, {});
};

export const setCurrentIssue = ({ commit }, issue = {}) => {
  commit(types.SET_CURRENT_ISSUE, issue);
};

export const setCurrentContribution = ({ commit }, contribution = {}) => {
  commit(types.SET_CURRENT_CONTRIBUTION, contribution);
};

export const removeCurrentSpace = ({ commit }) => {
  localStorage.removeItem('currentSpace');
  commit(types.SET_CURRENT_SPACE, {});
  commit(types.SET_CURRENT_SPACE_SIDEBAR_STATISTICS, {});
};

export const setCurrentGroup = ({ commit }, group) => {
  localStorage.setItem('currentGroup', JSON.stringify(group));
  commit(types.SET_CURRENT_GROUP, group);
};

export const removeCurrentGroup = ({ commit }) => {
  localStorage.removeItem('currentGroup');
  commit(types.SET_CURRENT_GROUP, {});
};

export const setCurrentQuestionnaire = ({ commit }, questionnaire) => {
  commit(types.SET_CURRENT_QUESTIONNAIRE, questionnaire);
};

export const removeCurrentQuestionnaire = ({ commit }) => {
  commit(types.SET_CURRENT_QUESTIONNAIRE, {});
};

export const setSidebarCollapsed = ({ commit }, collapsed) => {
  commit(types.SET_SIDEBAR_COLLAPSED, collapsed);
};

export const setInvisibleSidebar = ({ commit }, invisible) => {
  commit(types.SET_INVISIBLE_SIDEBAR, invisible);
};

export const setCurrentCommunity = ({ commit }, community) => {
  commit(types.SET_CURRENT_COMMUNITY, community);
};

export const removeCurrentCommunity = ({ commit }) => {
  commit(types.SET_CURRENT_COMMUNITY, {});
};

export const setCurrentFeedback = ({ commit }, feedback) => {
  commit(types.SET_CURRENT_FEEDBACK, feedback);
};

export const removeCurrentFeedback = ({ commit }) => {
  commit(types.SET_CURRENT_FEEDBACK, {});
};

export const setCurrentGoodResourcesTabs2 = ({ commit }, tabs) => {
  commit(types.SET_CURRENT_GOOD_RESOURCES_TABS_2, tabs);
};

export const removeCurrentGoodResourcesTabs2 = ({ commit }) => {
  commit(types.SET_CURRENT_GOOD_RESOURCES_TABS_2, []);
};

export const setSelectedFolder = ({ commit }, folder = {}) => {
  commit(types.SET_SELECTED_FOLDER, folder);
};

export const setCurrentFolder = ({ commit }, folder = {}) => {
  commit(types.SET_CURRENT_FOLDER, folder);
};

export const setPreUploads = ({ commit }, uploads = []) => {
  commit(types.SET_PRE_UPLOADS, uploads);
};
